<?php
namespace app\api\model;

use app\common\model\BaseModel;

/**
 * 订单模型
 * Class Order
 * @package app\api\model
 */
class Order extends BaseModel
{
    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    
    /**
     * 关联会员
     * @return \think\model\relation\BelongsTo
     */
    public function member()
    {
        return $this->belongsTo('Member', 'member_id');
    }
    
    /**
     * 获取订单状态文本
     * @param int $value
     * @return string
     */
    public function getStatusTextAttr($value, $data)
    {
        $status = [0 => '未支付', 1 => '已支付', 2 => '已取消', 3 => '已退款'];
        return isset($status[$data['status']]) ? $status[$data['status']] : '未知';
    }
    
    /**
     * 获取订单类型文本
     * @param int $value
     * @return string
     */
    public function getOrderTypeTextAttr($value, $data)
    {
        $types = [
            'membership' => '会员开通',
            'recharge' => '车币充值',
            'parking' => '停车缴费'
        ];
        return isset($types[$data['order_type']]) ? $types[$data['order_type']] : '未知';
    }
} 